package com.sixth.service.Impl;

import com.sixth.dao.StatisticsDao;
import com.sixth.entity.Goods;
import com.sixth.entity.OutlibraryGoods;
import com.sixth.entity.Staff;
import com.sixth.service.StatisticsService;
import com.sixth.util.LayTab;
import org.apache.http.client.methods.HttpOptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @program: project01
 * @description:
 * @author: 老范
 * @create: 2021-12-24 10:49
 **/
@Service
public class StatisticsServiceImpl implements StatisticsService {
    @Autowired
    private StatisticsDao statisticsDao;
    @Autowired
    private HttpSession session;
    public LayTab output(Goods goods, String start, String end, String value) {
        Staff staff = (Staff) session.getAttribute("staff");
        Integer branchid = staff.getBranchid();
        List<Map> output = statisticsDao.output(goods, branchid,start,end,value);
        if(output.size()>0){
            return new LayTab(output.size(),output);
        }
        return null;
    }

    public LayTab sale(OutlibraryGoods outLibraryGoods, String start, String end, String value) {
        List<Map> sale = statisticsDao.sale(outLibraryGoods,start,end,value);
        if(sale.size()>0){
            return new LayTab(sale.size(),sale);
        }
        return null;
    }

    public List<Double> sell(OutlibraryGoods outLibraryGoods,String start,String end,String value) {
        Staff staff = (Staff) session.getAttribute("staff");
        Integer branchid = staff.getBranchid();
        List<Map> sell = statisticsDao.sell(outLibraryGoods, branchid,start,end,value);
        List<Map> buy = statisticsDao.buy(branchid,start,end,value);
        Double jinjia = (Double) buy.get(0).get("jinjia");
        Double shoujia = (Double) sell.get(0).get("shoujia");
        ArrayList<Double> doubles = new ArrayList<>();
        doubles.add(jinjia);
        doubles.add(shoujia);
        if(sell.size()>0){
            return doubles;
        }
        return null;
    }


}
